home *** CD-ROM | disk | FTP | other *** search
-
- ********************************************************************
- ************************ FWRITE by Rex Kerr ************************
- ************************ Copyright (C) 1989 ************************
- ********************************************************************
-
- This is a Turbo Pascal 5.5 unit written mostly in assembly
- language. It has 12 routines for reading/writing and 7 that
- affect how the 12 other routines work.
-
- ***
-
- VramCh(x,y : byte; ch : char; attr : byte);
-
- This writes the character ch in attribute attr at X,Y on the screen.
- Note that VramCh pays no attention to any windows that might be
- on the screen--all coordinates are absolute screen coordinates.
- If you use the CRT unit in your program, you can write in the
- current text color using the CRT variable TextAttr (like this:)
-
- vramch(xpos,ypos,ch,textattr); { Only textattr needs to stay the same
- to write in TP's text color }
-
- ***
-
- GetVramCh(x,y : byte; var ch : char; attr : byte);
-
- This reads the character and attribute at X,Y. See VramCh.
-
- ***
-
- VramCharRpt(count : byte; x,y : byte; ch : char; attr : byte);
-
- This repeats one character and attribute starting at x,y and
- repeating count times. It is useful for clearing a portion of
- the screen, for example:
-
- program clearwindow(windowx,windowy,windowx2,windowy2 : byte);
- var tempbyte : byte;
- i : integer;
- begin
- for i := windowy to windowy2 do
- begin
- tempbyte := (windowx2 - windowx) + 1;
- vramcharrpt(tempbyte,windowx,i,' ',textattr);
- end;
- end;
-
- That procedure will fill the window (defined by windowx, windowy,
- windowx2, windowy2) with spaces in the current text attribute.
-
- ***
-
- VramLineCopy(count : byte; x,y : byte; x2,y2 : byte);
-
- This copies count characters (and attributes) starting at X,Y
- and going to X2,Y2. It works about the same as
-
- procedure false_vramlcopy(count,x,y,x2,y2 : byte);
- var i,atr : byte;
- ch : char;
- begin
- for i := 0 to count-1 do
- begin
- getvramch(x+i,y,ch,attr);
- vramch(x2+i,y2,ch,attr);
- end;
- end;
-
- except it is much much faster.
-
- ***
-
- VramWrit(x,y : byte; attr : byte; st : string);
-
- This writes the string st in attribute attr starting at X,Y.
-
- It will NOT scroll the screen up when it goes off the end of the
- last line, and it does not interpret chars #7,8,10 and 13.
-
- ***
-
- ClrVramLine(line : byte; attr : byte);
-
- This clears the line specified with the attribute specified.
-
- ***
-
- ClrVram(attr : byte);
-
- This clears the whole screen with the attribute specified.
-
- ***
-
- VramScroll(lines : shortint; x,y,w,h : byte; attr : byte);
-
- This scrolls the defined window (that is, a window the same size as
- you would get with window(x,y,w,h); ) up the indicated number of
- lines. New lines will be blank in the attribute attr. To scroll
- the screen down, pass a negative number.
-
- Note: To save speed, scroll as many lines as possible at one time.
-
- Instead of writing
-
- vramscroll(1,1,1,80,25,7);
- vramwrit(1,25,7,'This is the');
- vramscroll(1,1,1,80,25,7);
- vramwrit(1,25,7,'slow way to');
- vramscroll(1,1,1,80,25,7);
- vramwrit(1,25,7,'scroll this.');
-
- you should write
-
- vramscroll(3,1,1,80,25,7);
- vramwrit(1,23,7,'This is the');
- vramwrit(1,24,7,'fast way to');
- vramwrit(1,25,7,'do this.');
-
- ***
-
- VramLine(x,y : byte; start,count : byte; var lin);
-
- This is meant to write count chars and attrs (starting at X,Y on the
- screen (and start in lin)) from the predefined type, vram_line, which
- is defined as:
-
- type vram_line = array[1..80][1..2] of byte;
-
- in FWRITE.
- However, you can pass any variable you want...but be sure you don't
- overrun it.
-
- ***
-
- GetVramLine(x,y : byte; start,count : byte; var lin);
-
- This does the same thing as VramLine, except it reads into lin
- instead of writing from it.
-
- ***
-
- PutVramSec(var scrn; x,y,w,h : byte; x2,y2 : byte);
-
- This is meant to copy a window on the screen (x,y,w,h) from scrn
- (starting at x2,y2 in scrn). Scrn is meant to be the predefined
- type Vram_ScrBuf, which is defined as
-
- type Vram_ScrBuf = array[1..25] of Vram_Line;
-
- but any variable large enough can be used.
-
- ***
-
- GetVramSec(var scrn; x,y,w,h : byte; x2,y2 : byte);
-
- This is putvramsec's twin. It does the same as putvramsec, except
- it reads from the screen instead of writes to it.
-
- ***
-
- Get_Display(var screenseg : word);
-
- This returns $B000 if the monitor is monochrome, otherwise it
- assumes CGA and returns $B800. It is normally used on the
- variable Vid_Mem_Start. You can set Vid_Mem_Start yourself if
- you want to write to an EGA or VGA display, for example.
- Card Segment
- Monochrome $B000
- CGA $B800
- EGA $A000
- VGA $A000
-
- Note: EGAs and VGAs start at $A000 in graphics mode. I am not sure
- where they start in "large" mode. In CGA mode (80*25), they
- start at $B800.
-
- ***
-
- SetVramOfs(ofst : word);
-
- This sets the offset of screen memory. For the real screen, it
- should always be 0. However, you may want to define a "fake" screen.
- Assuming FakeBuf is an array at least 4000 bytes long, you can do
- this to set up a fake screen to read from and write to:
-
- vid_mem_start := seg(fakebuf);
- setvramofs(ofs(fakebuf));
-
- Now, all reads and writes will be to and from fakebuf, just like it
- was the real screen. To write back to the old screen (assuming
- Get_Display works for you) you simply do:
-
- get_display(vid_mem_start);
- setvramofs(0);
-
- If get_display doesn't work, you'll have to save the old mode in
- a variable:
-
- var a : word;
- b : vram_scrbuf;
-
- begin
- vid_mem_start := $B500; { Wierd display, but... }
- ( . . . ) { Do some stuff }
- a := vid_mem_start; { Save the address }
- vid_mem_start := seg(b); { Set the segment address }
- setvramofs(ofs(b)); { Set the offset address }
- ( . . . ) { Write to b instead of screen }
- vid_mem_start := a; { Get the old address back again }
- setvramofs(0); { Now you can write to the screen }
- end.
-
- ***
-
- GetVramOfs : word;
-
- This gets the current offset.
-
- ***
-
- SetVramMaxX(lines : byte);
-
- This sets the length of the lines on the screen. Useful for both
- "fake" screens which are smaller (50*20, maybe) or EGA and VGA modes
- where the lines are longer than normal.
-
- ***
-
- GetVramMaxX : byte;
-
- This gets the set length of the lines on the screen.
-
- ***
-
- SetVramMaxY(lines : byte);
-
- This sets the length of the screen in lines. It isn't really used
- except in ClrVram. The others never check to see if they are going
- off the end of the screen.
-
- ***
-
- GetVramMaxY : byte;
-
- This gets the set length of the screen in lines.
-
- ***
-
- Two warnings:
-
- 1) FWRITE will cause snow on snowy CGAs. I haven't yet found out
- how to not cause snow and not slow down good monitors too much.
- 2) FWRITE never checks to see that you have valid parameters. If
- your screen is 80*25 and to do vramch(90,30,ch,textattr), It will
- write the character out anyway. This is usually fine for the real
- screen. However, when you are writing to a "fake" screen, you have
- to be careful, because if you run over the end of the buffer, you
- will most likely be overwriting something you didn't want to.
-
- Also note that FWRITE never moves the cursor, and always reads from
- absolute screen coordinates (i.e. 1,1 is always the top left corner
- of the screen, no matter what windows you set).
-
- This is version 1.2 of FWRITE. Version 1.0 had a bug in the
- scrolling routine. The scrolling is now faster, and it works the
- right way, too. To my knowledge, FWRITE is faster than any other
- units for Turbo Pascal that write directly to screen memory.